package org.restoran.service.parser;

import java.io.Writer;
import java.util.Collection;

/**
 * Base interface for parsing entities
 *
 * @author Snisar Bogdan.
 */
public interface Parser {

        /**
         * Parse entity to custom json
         * @param entity entity object
         * @return  json as String
         */
        <E> String toJson(E entity);

        /**
         * Write parsed json, by entity fields, string to {@link java.io.Writer}
         * @param writer {@link java.io.Writer}
         * @param entity parse entity
         * @return
         */
        <E> void toJson(Writer writer, E entity);

    /**
     * Parse all entityes from collection and return json array
     * @param objects Collection
     * @param <E> type
     * @return json array as {@link String}
     */
        <E> String toJson(Collection<E> objects);


    /**
     * Parse all entityes from collection and return json array
     * @param args Collection
     * @param writer {@link Writer} writer for json result
     * @param <E> type
     */
        <E> void toJson(Writer writer, Collection<E> args);

        /**
         * Parse to entity json by using some custom format.
         * @param json json string
         * @param type type for entity
         * @return entity instance
         */
        <E> E fromJson(String json, Class<E> type);
}
